<template>
  <div>
    <div><h1>自主入库</h1></div>
    <div>
      <div>
        <el-form :inline="true" :model="date" :label-position="right" label-width="120px">
          <el-form-item label="车号:">
            <el-input v-model="date.chehao" class="saptext" type="text"></el-input>
          </el-form-item>
        </el-form>
      </div>

      <div class="form-container">
        <el-form :inline="true" v-model="date" :label-position="right" label-width="120px">
          <el-form-item label="供货方:">
            <el-select class="ymhttext" v-model="date.ghf" placeholder="请选择">
              <el-option
                v-for="item in ymhthOptions"
                :key="item.id"
                :label="item.text"
                :value="item.text">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="收货方:">
            <el-input class="jhlxtext" v-model="date.shf" type="text"/>
          </el-form-item>
          <el-form-item label="货物名称:">
            <el-input class="jhrqtext" v-model="date.hwmc" type="text"/>
          </el-form-item>
          <el-form-item label="仓库编号:">
            <el-input class="gystext" v-model="date.ckbh" @change="selectckbh" type="text"/>
          </el-form-item>
          <el-form-item label="仓库名称:">
            <el-input class="gysmctext" v-model="date.ckmc" type="text"/>
          </el-form-item>
          <el-form-item label="原始单号:">
            <el-input class="sjxmtext" v-model="date.ysdh" type="text"/>
          </el-form-item>
          <el-form-item label="原始重量:">
            <el-input class="chtext" v-model="date.yszl" type="text"/>
          </el-form-item>
          <el-form-item label="规格:">
            <el-input class="chtext" v-model="date.guige" type="text"/>
          </el-form-item>
          <el-form-item label="运输类型:">
            <el-input class="chtext" v-model="date.yslx" type="text"/>
          </el-form-item>
          <el-form-item label="物流名称:">
            <el-input class="chtext" v-model="date.wlmc" type="text"/>
          </el-form-item>
          <el-form-item label="第三方:">
            <el-input class="chtext" v-model="date.dsf" type="text"/>
          </el-form-item>
          <el-form-item label="手机号:">
            <el-input class="chtext" v-model="date.openid" type="text"/>
          </el-form-item>
        </el-form>
      </div>

      <div>
        <el-button @click="submitData">提交</el-button>
      </div>
    </div>
  </div>
</template>

<script>

import {
  selectshdz, selecttbck,

  tbGuozhongExists,
  tbGuozhonginsertsd, tbGuozhonginsertzz
} from "@/api/system/Fdongbei/zd";


export default {
  data() {
    return {
      right: "",
      date: {
        chehao: '',
        ghf: '',
        shf: '',
        hwmc: '',
        ckbh: '',
        ckmc: '',
        ysdh: '',
        yszl: '',
        guige: '',
        yslx: '',
        wlmc: '',
        dsf: '',
        openid: '',
      },
      ymhthOptions: [],
      guozhong: {
        chehao: '',
        cardId: '',
        czbh: '',
        wlmc: '',
        gysdm: '',
        gsmc: '',
        ckbh: '',
        ckmc: '',
        ddysdh: '',
        ddyszl: '',
        guige: '',
        yslx: '',
        wlmcc: '',
        gblx: '',
        czymc: '',
        gbzt: '',
        ymqysj: '',
        ddwlsl: '',
        wlbh: '',
        fkZdr: '',
        sdDwx: '',
        ddbh: '',
        sdBzwmc: '',
        kkRjbb: '',
        ycCcc: '',
        zzmtbs: '',
        songdf: '',
        fksj: '',

      }
    }
      ;
  },
  created() {
    this.fetchData();
  },
  methods: {
    fetchData() {
      selectshdz().then(response => {
        this.ymhthOptions = response.data
      })
    },
    selectckbh() {
      selecttbck({WERKS: '1600', lgort: this.date.ckbh}).then(response => {
        this.date.ckmc = response.data[0].lgobe
      })
    },
    submitData() {//提交
      if (this.date.chehao === "") {
        this.qk()
        this.$modal.alertWarning("车号不能为空")
        return;
      }

      tbGuozhongExists({chehao: this.date.chehao}).then(response => {
        if (response.msg === 'OK') {
          this.guozhong = {
            chehao: this.date.chehao,
            cardId: '',
            czbh: 'DR',
            wlmc: this.date.hwmc,
            gysdm: this.date.ghf,
            gsmc: this.date.shf,
            ckbh: this.date.ckbh,
            ckmc: this.date.ckmc,
            ddysdh: this.date.ysdh,
            ddyszl: this.date.yszl,
            guige: this.date.guige,
            yslx: this.date.yslx,
            wlmcc: this.date.wlmc,
            gblx: 'ZZ_R',
            czymc: this.$store.state.user.name,
            gbzt: '待进厂',
            ymqysj: '',
            ddwlsl: '',
            wlbh: '',
            fkZdr: this.$store.state.user.name,
            sdDwx: '',
            ddbh: '',
            sdBzwmc: '',
            kkRjbb: '',
            ycCcc: '',
            zzmtbs: '',
            songdf: '',
            fksj: new Date().toISOString(),
          }

          tbGuozhonginsertzz(this.guozhong).then(response => {
            if (response.msg !== 0) {
              this.qk()

              this.$modal.alert("保存成功")

            } else {
              this.qk()
              this.$modal.alertWarning("保存失败")

            }
          })
        } else {
          this.qk()
          this.$modal.alertWarning(response.msg)
        }
      })
    }


  },
  qk() {
    this.date = {
      chehao: '',
      ghf: '',
      shf: '',
      hwmc: '',
      ckbh: '',
      ckmc: '',
      ysdh: '',
      yszl: '',
      guige: '',
      yslx: '',
      wlmc: '',
      dsf: '',
      openid: '',
    },
      this.ymhthOptions = [],
      this.guozhong = {
        chehao: '',
        cardId: '',
        czbh: '',
        wlmc: '',
        gysdm: '',
        gsmc: '',
        ckbh: '',
        ckmc: '',
        ddysdh: '',
        ddyszl: '',
        guige: '',
        yslx: '',
        wlmcc: '',
        gblx: '',
        czymc: '',
        gbzt: '',
        ymqysj: '',
        ddwlsl: '',
        wlbh: '',
        fkZdr: '',
        sdDwx: '',
        ddbh: '',
        sdBzwmc: '',
        kkRjbb: '',
        ycCcc: '',
        zzmtbs: '',
        songdf: '',
        fksj: '',

      }
  }
};

</script>

<style scoped lang="scss">
.el-icon-searchsousuo {
  display: flex;
  align-items: center;
}

.el-input {
  width: auto;
  flex-grow: 3;
}

.el-button {
  margin-left: 10px; /* 调整按钮与输入框之间的间距 */
  flex-shrink: 0; /* 防止按钮在宽度不足时被压缩 */
}

.input-with-select {
  background-color: #fff;
}
</style>
